package ar.com.laley.centro.servicios;

import java.util.Iterator;
import java.util.List;

import ar.com.laley.centro.beans.Catedra;
import ar.com.laley.centro.beans.Materia;
import ar.com.laley.centro.dao.AjaxDAOImpl;


public abstract class ServicioAjax {

	public static String obtenerCatedras(int idMateria)throws Exception{

		List listaCatedras = null;
		String output = null;
		try{
			AjaxDAOImpl dao = new AjaxDAOImpl();
			listaCatedras = dao.obtenerCatedras(idMateria);
			if ((listaCatedras == null)||(listaCatedras.size() == 0)){
				throw new Exception();
			}
			else{
				StringBuffer stb = new StringBuffer();
				stb.append("|");
				Iterator it = listaCatedras.iterator();
				while (it.hasNext()){
					Materia mat = (Materia)it.next();
					Iterator it2 = mat.getCatedras().iterator();
					while (it2.hasNext()){
						Catedra cat = (Catedra)it2.next();
						stb.append("|"+cat.getCatedraNombre()+";"+cat.getCatedraId()+"|");
					}
				}
				output = stb.toString();
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return output;
	}

	public static String obtenerMaterias()throws Exception{

		List listaMaterias = null;
		String output = null;
		try{
			AjaxDAOImpl dao = new AjaxDAOImpl();
			listaMaterias = dao.obtenerMaterias();
			if ((listaMaterias == null)||(listaMaterias.size() == 0)){
				throw new Exception();
			}
			else{
				StringBuffer stb = new StringBuffer();
				stb.append("|");
				Iterator it = listaMaterias.iterator();
				while (it.hasNext()){
					Materia mat = (Materia)it.next();
					stb.append("|"+mat.getMateriaNombre()+";"+mat.getMateriaId()+"|");
				}
				output = stb.toString();
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return output;
	}
}
